{include file="public/toper"/}
<style>
    .layui-unselect{width: 190px;}
    .layui-form-select dl {width:190px;}
</style>
<div class="x-body">
    <form action="" method="post" class="layui-form" id="forms">
        <input name="prize_id" value="{$list.prize_id}" type="hidden" />
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>游戏名称</label>
            <div class="layui-input-inline">
                <select name="type">
                    <option value="0" {if condition = "$list.type eq 0 "}selected="selected"{/if}>夺宝奇兵</option>
                    <option value="1" {if condition = "$list.type eq 1 "}selected="selected"{/if}>刮刮乐</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>奖品名称
            </label>
            <div class="layui-input-inline">
                <input type="text" value="{$list.name}"  name="name" required="" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>20个字符
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>奖品图片
            </label>
            <div class="layui-input-inline layui-upload" id="upload-thumb">
                <button type="button" class="layui-btn layui-btn-primary" id="image"><i class="layui-icon"></i>上传图片</button>
                <div class="layui-upload-list">
                    {if condition = "$list.img  neq '' "}
                    <img src="{$list.img}" class="layui-upload-list" id="demo" width="100" height="100">
                    {else/}
                    <img class="layui-upload-list imgsc" id="demo">
                    <p id="demoText"></p>
                    {/if}
                </div>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>库存
            </label>
            <div class="layui-input-inline">
                <input type="number" value="{$list.stock}" name="stock" min="1" required="" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>5位数（0-32767）
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>中奖概率
            </label>
            <div class="layui-input-inline">
                <input type="number" value="{$list.chance}" name="chance" required="" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>2位数
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>奖品类型</label>
            <div class="layui-input-inline">
                <select name="prize_type" lay-filter="type">
                    <option value="0" {if condition = "$list.prize_type eq 0 "}selected="selected"{/if}>虚拟奖品自动领奖</option>
                    <option value="1" {if condition = "$list.prize_type eq 1 "}selected="selected"{/if}>虚拟奖品手动发放</option>
                    <option value="2" {if condition = "$list.prize_type eq 2 "}selected="selected"{/if}>实物奖品手动发放</option>
                    <option value="3" {if condition = "$list.prize_type eq 3 "}selected="selected"{/if}>谢谢参与</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item ljdz" style="display: none">
            <label class="layui-form-label">
                <span class="x-red">*</span>自动领奖地址
            </label>
            <div class="layui-input-inline">
                <input type="text" value="{$list.url}" name="url" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>50个字符，地址：Game/automaticCollection?coupons_id=XX，（XX是优惠券ID值）
            </div>
        </div>


        <div class="layui-form-item dizhi">
            <label class="layui-form-label"><span class="x-red">*</span>提供收货信息</label>
            <div class="layui-input-inline">
                <select name="provide">
                    <option value="0" {if condition = "$list.provide eq 0 "}selected="selected"{/if}>不需要</option>
                    <option value="1" {if condition = "$list.provide eq 1 "}selected="selected"{/if}>需要</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red"></span>领奖描述
            </label>
            <div class="layui-input-inline">
                <input type="text" value="{$list.desc}" name="desc" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>30个字符
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <button  class="layui-btn" lay-filter="formSubmit" lay-submit="">提交</button>
        </div>
    </form>
</div>

<script>
    layui.use(['form','upload'], function(){
        $ = layui.jquery;
        var form = layui.form,layer = layui.layer;
        var upload = layui.upload;


        //普通图片上传
        var uploadInst = upload.render({
            elem: '#image',
            url: "{:url('Upload/games')}",
            ext: 'jpg|png|gif',
            drag:false,
            before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo').attr('src', result); //图片链接（base64）
                });
            },
            done: function(res){
                //如果上传失败
                if(res.code == 200 ){
                    $('#upload-thumb').append('<input type="hidden" name="img" value="'+ res.data.src+'">');
                }else {
                    layer.msg(res.msg);
                }
                //上传成功
            },
            error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });

        var ljdz = {$list.prize_type};
        if(ljdz==0){
            $(".ljdz").css("display","block");
        }else if(ljdz==3) {
            $(".dizhi").css("display","none");
        }

        form.on('select(type)', function(data){
            if(data.value!=0){
                if(data.value==3){
                    $(".dizhi").css("display","none");
                }else {
                    $(".dizhi").css("display","block");
                }
                $(".ljdz").css("display","none");
                form.render('select', 'type');
            }else {
                $(".ljdz").css("display","block");
                $(".dizhi").css("display","block");
                form.render('select', 'type');
            }
        });

    });
</script>
{include file="public/footer"/}